home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14156 < prev    next >
Encoding:
Text File  |  1996-08-05  |  8.3 KB  |  321 lines

  1. Path: news.cc.utah.edu!not-for-mail
  2. From: dpncc@utah.state.ut.us (NCC Network)
  3. Newsgroups: comp.unix.programmer,comp.lang.c,comp.unix.internals
  4. Subject: C compiler Error on EXEC SQL
  5. Date: 12 Apr 1996 02:19:14 GMT
  6. Organization: University of Utah Computer Center
  7. Message-ID: <4kkej2$3ta@news.cc.utah.edu>
  8. NNTP-Posting-Host: utah.it.as.ex.state.ut.us
  9. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  10.  
  11.  
  12. Hi
  13.  
  14. I post this for my friend who has no access to the internet and would like to
  15. get help from C experts in the Net. She has a C program left over from a guy
  16. left the company. The C source code is included below as well as the compiler
  17. error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
  18. to be a standard C. 
  19.  
  20. I would appreciate any hints or comments.
  21. Thanks in advances.
  22.  
  23. Dennis. 
  24.  
  25.  
  26. -------------------- ERROR MESSAGE ----------------------------------------
  27.  
  28. I tried to compile "monthly_addup.c" and get the following error message:
  29.  
  30. (Bundled) cc:  line 4: error 1000: Unexpected symbol: "SQL".
  31. (Bundled) cc:  line 4: error 1000: Unexpected symbol: ";".
  32. (Bundled) cc:  line 12: error 1000: Unexpected symbol: "SQL".
  33. (Bundled) cc:  line 12: error 1000: Unexpected symbol: "DECLARE".
  34. (Bundled) cc:  line 24: error 1000: Unexpected symbol: "SQL".
  35. (Bundled) cc:  line 24: error 1000: Unexpected symbol: "DECLARE".
  36. (Bundled) cc:  line 50: error 1000: Unexpected symbol: "SQL".
  37. (Bundled) cc:  line 50: error 1000: Unexpected symbol: "'revenue'".
  38. ...............................
  39.  
  40. ----------------------------- C program ----------------------------
  41. This C program is originally named as "monthly_addup.ec".  It's not like
  42. the normal C program that ends with ".c".  
  43. Here is the source:
  44.  
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48. EXEC SQL include decimal.h;
  49.  
  50. /* Global variables */
  51. char month[3];              /* mm plus null zero to end string */
  52. char year[5];               /* yyyy plus null zero to end string */
  53. char month_name[10];        /* ex: September plus null zero to end string */
  54.  
  55. EXEC SQL BEGIN DECLARE SECTION;
  56.      long   per_id_revn_de;
  57.      long   loc_id_revn_de;
  58.      long   ind_id_revn_de;
  59.      long   ct_id_revn_de;
  60.      long   fee_id_revn_de;
  61.      long   dist_id_revn_de;
  62.      dec_t  amt_paid_revn_de;
  63.      dec_t  amt_credit_revn_de;
  64.      dec_t  amt_due_revn_de;
  65.      long   trans_count_p_revn_de;
  66.      long   trans_count_c_revn_de;
  67.      long   trans_count_d_revn_de;
  68. EXEC SQL END DECLARE SECTION;
  69.  
  70. EXEC SQL BEGIN DECLARE SECTION;
  71.      long per_id_perd_de;
  72.      char per_level_perd_de[16];     /* additional byte for null zero */
  73.      char per_desc_perd_de[16];
  74.      char week_perd_de[11];
  75.      char month_perd_de[11];
  76.      char quarter_perd_de[11];
  77.      char year_perd_de[5];
  78.      char fiscal_year_perd_de[6];
  79.      int  sequence_perd_de;
  80.      int  per_num_perd_de;
  81.      char cur_flag_perd_de;
  82. EXEC SQL END DECLARE SECTION; 
  83.  
  84. /* Main Program */
  85. main(argc,argv)       
  86. int argc;
  87. char *argv[];
  88. {
  89.  
  90. long per_id_for_month;
  91. int  num_recs_created = 0;
  92. char mmyyyy[7];
  93. char filename[40];
  94. double amt_paid, amt_credit, amt_due;
  95. int x;     
  96. FILE *fptr;
  97.  
  98. if (argc == 3)        
  99.    ;
  100. else
  101.    {
  102.    printf("Incorrect number of arguements\n");
  103.    printf("Usage: %s [mmyyyy] [output file and path] \n",argv[0]);
  104.    exit(8);   
  105.    }
  106.  
  107. if (strlen(argv[2]) > 40) 
  108.    {
  109.    printf("Path and filename arguement too long. ");
  110.    printf("Must not exceed 40 characters\n");
  111.    exit(8);
  112.    }
  113.  
  114. printf("\nMonthly Addup Program is running...\n\n");
  115.  
  116. strcpy(mmyyyy, argv[1]);
  117. strcpy(filename, argv[2]);
  118.  
  119. printf("Monthly data will be written to output file: %s\n", filename);
  120.  
  121. if ( (fptr = fopen(filename,"w")) == NULL )
  122.    {
  123.    printf("Cannot open output file: %s\n", filename);
  124.    exit(8);
  125.    }
  126.  
  127. edit_and_convert_date(mmyyyy);
  128.  
  129. printf("Monthly data is being generated for: %s %s\n",month_name, year);
  130.  
  131. EXEC SQL connect to 'revenue';
  132. if (SQLCODE != 0)
  133.    {
  134.    printf("SQL Error occurred on connect to database. ");
  135.    printf("SQLCODE is: %d\n", SQLCODE);
  136.    exit(8);   
  137.    }
  138.      
  139. EXEC SQL declare get_revenue cursor for
  140.      select loc_id,
  141.             ind_id,
  142.             ct_id,
  143.             fee_id,
  144.             dist_id,
  145.             sum(amt_paid),
  146.             sum(amt_credit),
  147.             sum(amt_due),
  148.             sum(trans_count_p),
  149.             sum(trans_count_c),
  150.             sum(trans_count_d)
  151.        into :loc_id_revn_de,
  152.             :ind_id_revn_de,
  153.             :ct_id_revn_de,
  154.             :fee_id_revn_de,
  155.             :dist_id_revn_de,
  156.             :amt_paid_revn_de,
  157.             :amt_credit_revn_de,
  158.             :amt_due_revn_de,
  159.             :trans_count_p_revn_de,
  160.             :trans_count_c_revn_de,
  161.             :trans_count_d_revn_de
  162.        from revenue
  163.       where per_id in (select per_id      
  164.                          from period
  165.                         where per_level = "Week"         and
  166.                               month     = :month_perd_de and   
  167.                               year      = :year_perd_de)
  168.    group by loc_id, ind_id, ct_id, fee_id, dist_id 
  169.    FOR READ ONLY;
  170.  
  171.  
  172. strcpy(year_perd_de,year);
  173. strcpy(month_perd_de,month_name);
  174.  
  175. EXEC SQL
  176.      select per_id
  177.        into :per_id_perd_de
  178.        from period
  179.       where per_level = "Month"        and
  180.             month     = :month_perd_de and
  181.             year      = :year_perd_de;
  182.  
  183. per_id_for_month = per_id_perd_de;
  184.  
  185. strcpy(month_perd_de,month_name);
  186. strcpy(year_perd_de,year);
  187. EXEC SQL open get_revenue;
  188. if (SQLCODE != 0)
  189.    {
  190.    printf("SQL Error occurred on open cursor get_revenue.  ");
  191.    printf("SQLCODE is: %d\n", SQLCODE);
  192.    exit(8);   
  193.    }
  194.  
  195. EXEC SQL fetch get_revenue;
  196. while (SQLCODE == 0)
  197.     {
  198.     if (x = dectodbl(&amt_paid_revn_de, &amt_paid)) 
  199.        {
  200.       printf("Error %d converting DECIMAL amt_paid_revn_de to DOUBLE\n",x);
  201.       exit(8);
  202.        }
  203.     if (x = dectodbl(&amt_credit_revn_de, &amt_credit))
  204.        {
  205.       printf("Error %d converting DECIMAL amt_credit_revn_de to DOUBLE\n",x);
  206.        exit(8);
  207.        }
  208.     if (x = dectodbl(&amt_due_revn_de, &amt_due))
  209.        {
  210.        printf("Error %d converting DECIMAL amt_due_revn_de to DOUBLE\n",x);
  211.        exit(8);
  212.        }
  213.           
  214.     fprintf(fptr, "%ld|",per_id_for_month);
  215.     fprintf(fptr, "%ld|",loc_id_revn_de);
  216.     fprintf(fptr, "%ld|",ind_id_revn_de);
  217.     fprintf(fptr, "%ld|",ct_id_revn_de);
  218.     fprintf(fptr, "%ld|",fee_id_revn_de);
  219.     fprintf(fptr, "%ld|",dist_id_revn_de);
  220.     fprintf(fptr, "%.2f|",amt_paid);
  221.     fprintf(fptr, "%.2f|",amt_credit);
  222.     fprintf(fptr, "%.2f|",amt_due);
  223.     fprintf(fptr, "%ld|",trans_count_p_revn_de);
  224.     fprintf(fptr, "%ld|",trans_count_c_revn_de);
  225.     fprintf(fptr, "%ld|",trans_count_d_revn_de);
  226.     fprintf(fptr, "\n");
  227.  
  228.     num_recs_created = num_recs_created + 1;
  229.     EXEC SQL fetch get_revenue;  
  230.  
  231.     }
  232.  
  233. if (SQLCODE != 0 && SQLCODE != 100)
  234.    {
  235.    printf("SQLCODE is: %d\n",SQLCODE);
  236.    exit(8);   
  237.    }
  238.  
  239. printf("Number of load records created: %d\n",num_recs_created);
  240.  
  241. fclose(fptr);
  242.  
  243. EXEC SQL close get_revenue;  
  244. EXEC SQL free get_revenue; 
  245.  
  246. EXEC SQL disconnect current;
  247.  
  248. printf("\nMonthly Addup Program completed...\n\n");
  249. return(0);
  250. }
  251.  
  252.  
  253. /* Function to edit the month and year entered.  Convert the month */
  254. /* to a literal (02 --> February)                                  */
  255.  
  256. edit_and_convert_date(mmyyyy)    
  257. char *mmyyyy;
  258.  
  259. {
  260. int i, j;
  261. int month_num, year_num;
  262.  
  263. j=0;
  264. for (i=0; i<2; i++) 
  265.     {
  266.     month[j] = mmyyyy[i];
  267.     j++;
  268.     }
  269. month[j] = '\0';
  270.  
  271. j=0;
  272. for (i=2; i<6; i++)
  273.     {
  274.     year[j] = mmyyyy[i];
  275.     j++;
  276.     }
  277. year[j] = '\0';
  278.  
  279. month_num = atoi(month);
  280. year_num = atoi(year);
  281.  
  282. switch (month_num)
  283.    {
  284.    case 1:  strcpy(month_name,"January");
  285.             break;
  286.    case 2:  strcpy(month_name,"February");
  287.             break;
  288.    case 3:  strcpy(month_name,"March");
  289.             break;
  290.    case 4:  strcpy(month_name,"April");
  291.             break;
  292.    case 5:  strcpy(month_name,"May");
  293.             break;
  294.    case 6:  strcpy(month_name,"June");
  295.             break;
  296.    case 7:  strcpy(month_name,"July");
  297.             break;
  298.    case 8:  strcpy(month_name,"August");
  299.             break;
  300.    case 9:  strcpy(month_name,"September");
  301.             break;
  302.    case 10: strcpy(month_name,"October");
  303.             break;
  304.    case 11: strcpy(month_name,"November");
  305.             break;
  306.    case 12: strcpy(month_name,"December");
  307.             break;
  308.    default: printf("Invalid month value.  Value is: %d\n",month_num);
  309.             exit(8);   
  310.    }
  311.  
  312. if (year_num > 1900 && year_num < 2100)
  313.    ;
  314. else
  315.    {
  316.    printf("Invalid year value.  Value is: %d\n",year_num);
  317.    exit(8);
  318.    }
  319. }
  320.  
  321.